import os
from pathlib import Path
from pydantic import Field, field_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
from dotenv import load_dotenv

# 加载 .env 文件
env_path = Path(__file__).parent.parent / ".env"
if env_path.exists():
    load_dotenv(env_path)


class Settings(BaseSettings):
    model_config = SettingsConfigDict(env_prefix="", case_sensitive=False)

    app_name: str = Field(default="Recruiting API")
    db_url: str = Field(default="sqlite+aiosqlite:///./dev.db")
    jwt_secret: str = Field(default="changeme")

    # @field_validator("jwt_secret")
    # @classmethod
    # def validate_jwt_secret(cls, v: str) -> str:
    #     # Allow shorter secrets for testing environment
    #     if v == "changeme" or (len(v) < 32 and not v.startswith("test")):
    #         raise ValueError("JWT_SECRET must be at least 32 characters long and not the default value")
    #     return v


settings = Settings() 